/**
 * 通知api服务接口
 * @author lian
 */

import type { CreateNotificationParam, NotificationType } from '@/common/types/request'
import { NotificationApi } from '@/common/constants/request-api'
import { Method } from '@/common/enum/request-methods'

/**
 * 根据通知类型id获取通知信息
 * @param notificationType 通知类型id
 * @author lian
 */
export const getNotificationService = (notificationType: NotificationType) => {
  const url = replaceParams(NotificationApi.GET_NOTIFICATIONS_BY_TYPE_ID, [
    {
      paramName: 'typeId',
      value: notificationType,
    },
  ])

  return useRequest<Notification[]>({
    method: Method.GET,
    url,
    data: {
      notificationType,
    },
  })
}

/**
 * 创建通知
 * @param data 通知信息
 * @author lian
 */
export const createNotificationService = (data: CreateNotificationParam) => {
  return useRequest({
    method: Method.POST,
    url: NotificationApi.CREATE_NOTIFICATIONS,
    data,
  })
}

export const getSystemNotificationService = () => {
  return useRequest<Notification[]>({
    method: Method.GET,
    url: NotificationApi.GET_SYSTEM_NOTIFICATION,
  })
}

export const getActivityNotificationService = () => {
  return useRequest<Notification[]>({
    method: Method.GET,
    url: NotificationApi.GET_ACTIVITY_NOTIFICATION,
  })
}

/**
 * 根据通知id删除通知
 * @param notificationId
 * @author lian
 */
export const deleteNotificationByIdService = (notificationId: number) => {
  const url = replaceParams(NotificationApi.GET_NOTIFICATIONS_BY_TYPE_ID, [
    {
      paramName: 'id',
      value: notificationId,
    },
  ])

  return useRequest({
    method: Method.DELETE,
    url,
  })
}
